package com.atguigu.ssyx.product.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.product.service.ICategoryService;
import com.atguigu.ssyx.product.service.ISkuInfoService;
import com.atguigu.ssyx.vo.product.CategoryQueryVo;
import com.atguigu.ssyx.vo.product.SkuInfoQueryVo;
import com.atguigu.ssyx.vo.product.SkuInfoVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-23
 */
@RestController
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {


    @Autowired
    private ISkuInfoService skuInfoService;

    @ApiOperation(value = "获取sku分页列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<SkuInfo>> index(@ApiParam(name = "page", value = "当前页码", required = true) @PathVariable Long page,

                                        @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable Long limit,

                                        @ApiParam(name = "skuInfoQueryVo", value = "查询对象", required = false) SkuInfoQueryVo skuInfoQueryVo) {

        Page<SkuInfo> pageParam = new Page<>(page, limit);
        IPage<SkuInfo> pageModel = skuInfoService.selectPage(pageParam, skuInfoQueryVo);
        return Result.ok(pageModel);
    }


    @ApiOperation(value = "添加商品的sku" + "信息")
    @PostMapping("save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo) {
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok(null);
    }


    @ApiOperation(value = "根据id获得信息.")
    @GetMapping("get/{id}")
    public Result getInfoById(@PathVariable Long id) {
        SkuInfo skuInfo = skuInfoService.getSkuInfo(id);
        return Result.ok(skuInfo);
    }


    @ApiOperation(value = "修改")
    @PutMapping("update")
    public Result updateById(@RequestBody SkuInfoVo skuInfoVo) {
        skuInfoService.updateSkuInfo(skuInfoVo);
        return Result.ok();
    }


    /**
     * 商品上下架
     *
     * @param skuId
     * @return
     */
    @GetMapping("publish/{skuId}/{status}")
    public Result publish(@PathVariable("skuId") Long skuId, @PathVariable("status") Integer status) {
        skuInfoService.publish(skuId, status);
        return Result.ok();
    }

    //审核状态
    @ApiOperation("商品审核")
    @GetMapping("check/{id}/{status}")
    public Result check(@PathVariable("id") Long id, @PathVariable Integer status) {
        skuInfoService.check(id, status);
        return Result.ok();
    }


    //新人专享
    @GetMapping("isNewPerson/{skuId}/{status}")
    public Result isNewPerson(@PathVariable("skuId") Long skuId,
                              @PathVariable("status") Integer status) {
        skuInfoService.isNewPerson(skuId, status);
        return Result.ok();
    }
}

